﻿using IMES.Common.Domain.KeepModel.Process;
using IMES.Common.Dtos;
using IMES.Common.Infrastructure;
using MediatR;
using Org.BouncyCastle.Asn1.Ocsp;

namespace Keep.API.Appliction.Command.ProcessFile
{
    /// <summary>
    /// 处理工序类型命令
    /// </summary>
    public class WorkingProcedureTypeHandler: IRequestHandler<WorkingProcedureTypeCommon,Result>
    {
        private readonly IBaseRepositorys<WorkingProcedureType> _WorkingProcedureRep;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="WorkingProcedureRep"></param>
        public WorkingProcedureTypeHandler(IBaseRepositorys<WorkingProcedureType> WorkingProcedureRep)
        {
            _WorkingProcedureRep = WorkingProcedureRep;
        }
        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<Result> Handle(WorkingProcedureTypeCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CodeEnum.success, Messege = "处理工序类型成功" };
            try
            {
                var workingProcedureType = _WorkingProcedureRep.GetAll();
                    if (workingProcedureType == null)
                {
                    result.Code = (int)CodeEnum.search;
                    result.Messege = "未找到该工序类型";
                    return Task.FromResult(result);
                }
                    result.Data = workingProcedureType;
                
            }
            catch (Exception ex)
            {
                result.Code = (int)CodeEnum.error;
                result.Messege = ex.Message;
            }
            return Task.FromResult(result);


        }
    }
}
